package com.example.hanfu_bk.service;

import com.example.hanfu_bk.mapper.Home;
import com.example.hanfu_bk.pojo.Dynasty;
import com.example.hanfu_bk.pojo.Hanfu;
import com.example.hanfu_bk.pojo.StoryBox;
import com.example.hanfu_bk.pojo.Swiper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class HomeService {
    @Autowired
    private Home home;
    public List<Swiper> getActiveSwipers(){
        List<Swiper> allSwipers = home.selectAlSwiper();
        return allSwipers.stream().filter(swiper -> swiper.getActive() == 1).sorted(Comparator.comparing(Swiper::getSort).reversed()).collect(Collectors.toList());
    }
    public List<StoryBox> getActiveStoryBoxes(){
        List<StoryBox> allStoryBox = home.selectBox();
        return allStoryBox.stream().filter(storyBox -> storyBox.getActive() == 1).sorted(Comparator.comparing(StoryBox::getSort).reversed()).collect(Collectors.toList());
    }
    public Dynasty getDynastyById(int id) {
        return home.selectDynasty(id);
    }
    public String getContentById(int id) {
        return home.selectContentById(id);
    }
}
